package client;

import java.util.*;

import pojo.*;
import chatservice.IRoomService;

import org.codehaus.xfire.XFireFactory;
import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.service.*;
import org.codehaus.xfire.service.binding.*;
import java.net.MalformedURLException;

public class RoomClient {
	
	IRoomService srvc;
	public RoomClient()
	{
		Service srvcModel= new ObjectServiceFactory().create(IRoomService.class);
		XFireProxyFactory factory=new XFireProxyFactory(XFireFactory.newInstance().getXFire());
		
		String userURL="http://localhost:8080/ToolService/services/RoomService";
		
		try{
			srvc=(IRoomService)factory.create(srvcModel,userURL);
		//	System.out.println(" Room Client run");
			/*Vector<String> roomlist=srvc.getAllRooms();
			for(int i=0;i<roomlist.size();i++)
			{
				System.out.println("RoomName: "+roomlist.get(i));
			}*/
			
			
		}catch(MalformedURLException e)
		{
			e.printStackTrace();
		}
	}
	public Vector<String> getAllRooms()
	{
		Vector<String> roomlist=srvc.getAllRooms();
		return roomlist;
	}
	public int createRoom(String username,String roomname)
	{
		return srvc.createRoom(username, roomname);
	}
	public Vector<String> selectRoom(String username,String roomname)
	{
		Vector<String> userlist=srvc.selectRoom(username, roomname);
		return userlist;
	}
	public void   changeRoom(String username,String roomname)
	{
		srvc.changeRoom(username, roomname);
	}
	public Vector<String> getUserList(int roomid)
	{
		Vector <String>userlist=srvc.getUsersByRoomId(roomid);
		return userlist;
	}
	public Vector<String> getUserList(String roomname)
	{
		Vector <String>userlist=srvc.getUsersByRoomName(roomname);
		return userlist;
	}
}
